﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Program_Linq
{
    public class User
    {
        public Guid Id { get; set; }
        public UserInfo UserInfo { get; set; }

        public override string ToString()
        {
            return $"ID:{Id}，\n\r{UserInfo.ToString()}\n\r";
        }
    }

    public class UserInfo 
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public double Height { get; set; }
        public double Weight { get; set; }
        public string Introduce { get; set; }

        public override string ToString()
        {
            return $"Name:{Name}\n\r" +
                   $"Age：{Age}\n\r" +
                   $"Height:{Height}\n\r" +
                   $"Weight:{Weight}\n\r" +
                   $"Introduce:{Introduce}";
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<User> users1 = new List<User>()
            {
                new User
                {
                    Id = Guid.NewGuid(),
                    UserInfo = new UserInfo
                    {
                        Name = "嘉然",
                        Age = 21,
                        Height = 155,
                        Weight = 86,
                        Introduce = "Virtual"
                    }
                },
                new User
                {
                    Id = Guid.NewGuid(),
                    UserInfo = new UserInfo
                    {
                        Name = "向晚",
                        Age = 20,
                        Height = 165,
                        Weight = 88,
                        Introduce = "Virtual"
                    }
                }
            };

            List<User> users2 = new List<User>()
            {
                new User
                {
                     Id = Guid.NewGuid(),
                    UserInfo = new UserInfo
                    {
                        Name = "陈某",
                        Age = 21,
                        Height = 175,
                        Weight = 155,
                        Introduce = "Reality"
                    }
                },
                new User
                {
                    Id = Guid.NewGuid(),
                    UserInfo = new UserInfo
                    {
                        Name = "邱某某",
                        Age = 20,
                        Height = 175,
                        Weight = 110,
                        Introduce = "Reality"
                    }
                }
            };

            var result1 = from item in users1.Concat(users2)
                          where item.UserInfo.Age <= 20
                          select item;

            var result2 = users1.Concat(users2).Where(x => x.UserInfo.Age <= 20).ToList();

            Console.WriteLine("Result1 >>");
            result1.ToList().ForEach(item =>
            {
                Console.WriteLine(item.ToString());
            });

            Console.WriteLine("Result2 >>");
            result2.ForEach(item =>
            {
                Console.WriteLine(item.ToString());
            });

            Console.ReadLine();
        }
    }
}
